/* Copyright (c) 2004-2024 Peigen.info. All rights reserved. */

package info.peigen.hotpot.business.customer.core.service.processor.check;

import cn.hutool.core.lang.Assert;
import info.peigen.hotpot.business.customer.core.repository.entity.CustomerOperatorEntity;
import info.peigen.hotpot.business.customer.core.service.processor.base.AbstractCustomerServiceProcessor;
import info.peigen.hotpot.business.customer.facade.order.login.CustomerLoginOrder;
import info.peigen.hotpot.common.core.result.ResultCode;
import info.peigen.hotpot.common.service.base.exception.BusinessException;
import info.peigen.hotpot.common.service.base.processor.Processor;
import info.peigen.hotpot.common.service.base.processor.ProcessorServiceContext;
import org.noear.solon.annotation.Component;


/**
 * <b>(CustomerLoginCheckProcessor)</b>
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2023/8/30
 */
@SuppressWarnings("rawtypes")
@Component
public class CustomerLoginCheckProcessor extends AbstractCustomerServiceProcessor implements Processor {

    @Override
    public Integer level() {
        return 10;
    }

    @Override
    public void execute(ProcessorServiceContext serviceContext) {
        CustomerLoginOrder order = (CustomerLoginOrder) serviceContext.getOrder();
        order.check();

        CustomerOperatorEntity entity = customerRepository.getCustomerOperatorRepository().getMapper().findByLoginName(order.getLoginName());
        Assert.notNull(entity, () -> new BusinessException(ResultCode.FAILURE, "未注册!"));
        order.setCustomerId(entity.getCustomerId());
    }
}
